#include "wc3refcnt.h"
#include "Extern_global_Variable.h"

procedure TRefCnt::Release()
{
	__asm
	{
		mov ecx, this
	}
		(*(PRefCnt_VMT)vtable).Release();
}

procedure TRefCnt::IncRef()
{
	References++;
}

procedure TRefCnt::DecRef()
{
	References--;

	if (References == 0)
	{
		Release();
	}
}

procedure wc3refcnt_Init()
{
	p_TRefCnt_VMT = (PRefCnt_VMT)Pointer(GameDll+0x8765F8);
}

void wc3refcnt_main()
{
	wc3main_SubscribeOnInit(&wc3refcnt_Init);
}
